package com.java.huxb.day06.utils;

import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.java.huxb.day06.TicketRunnable;

import java.util.concurrent.*;

/**
 * @author huxb
 * @date 2020/4/4 0004 下午 5:42
 */
public class ThreadUtils {
    private  static ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("thread-call-runner-%d").build();
    private static ExecutorService executorService = new ThreadPoolExecutor(10,20,200L, TimeUnit.MILLISECONDS,new LinkedBlockingQueue<Runnable>(),namedThreadFactory);


    /**
     * 执行线程任务
     * @param runnable
     */
    public static void execute(Runnable runnable) {
        executorService.execute(runnable);
    }

    public static void showDwon() {
        executorService.shutdown();
    }
    public static void main(String[] args) {

        Integer size =  5;
        TicketRunnable ticketRunnable = new TicketRunnable();
        for (Integer i = 0; i < size; i++) {
            ThreadUtils.execute(ticketRunnable);
        }

        ThreadUtils.showDwon();
    }
}
